package com.konne.nightmare.FastPublicOpinion.ui.personal.adapter;

import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.konne.nightmare.FastPublicOpinion.R;
import com.konne.nightmare.FastPublicOpinion.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: chen
 * @UpdateDate: 1/22/22 4:47 PM
 * @UpdateRemark: 设备管理
 */
public class DeviceAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private OnDeleteClickLister mDeleteClickListener;

    public DeviceAdapter(int layoutResId, @Nullable List<String> data) {
        super(layoutResId, data);

    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        View line = helper.getView(R.id.view_line);
        if (helper.getLayoutPosition() == getItemCount()-1) {
            line.setVisibility(View.GONE);
        }
        TextView tvName = (TextView) helper.getView(R.id.tv_device_name);
        TextView tvDelete = (TextView) helper.getView(R.id.tv_delete);
        tvName.setText(item);
        tvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDeleteClickListener.onDeleteClick(v, helper.getLayoutPosition());
            }
        });
    }

    public void setOnDeleteClickListener(OnDeleteClickLister listener) {
        this.mDeleteClickListener = listener;
    }

    public interface OnDeleteClickLister {
        void onDeleteClick(View view, int position);
    }
}
